package com.report;

import java.awt.Color;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class ReportTest extends org.apache.struts.actions.DispatchAction {
//<set> 中的属性
//	value                        数据值
//	color                        颜色
//	link                        链接（本窗口打开[Url]，新窗口打开[n-Url]，调用JS函数[JavaScript:函数]）
//	name                        横向坐标轴标签名称
	/**
	 * 饼图
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward pieImage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {


//		c.get
		StringBuffer sb = new StringBuffer();
		//bgColor='ffffff' bgAlpha='100' 背景颜色 和 透明度
		//showPercentageValues='1'  显示百分比
		//baseFontSize='12' 字体大小
		//numberPrefix='$'  numberSuffix='%' 数值前缀 、 后缀
		//labelDisplay='ROTATE' 柱状文字排列方式 默认WRAP
		// xAxisName='Quarter' yAxisName='Sales'  x轴显示  y轴显示
		//指定 每一柱的颜色 paletteColors='FF5904,0372AB,FF0000'
		//截取图像部分yAxisMinValue='0' yAxisMaxValue='100'
		//图边距 chartLeftMargin='10' chartTopMargin='10' chartRightMargin='15' chartBottomMargin='10'
		//caption='主标题' subcaption ="次标题" xAxisName='x轴显示'
		//xAxisName='Quarter' yAxisName='Sales'
		//chartLeftMargin='0' chartTopMargin='0' chartRightMargin='0' chartBottomMargin='0'
		//palette='4' toolTipBorderColor='D9E5F1' chartLeftMargin='0' chartTopMargin='0' chartRightMargin='0' chartBottomMargin='0' 
		//toolTipBgColor='D9E5F1' labelDisplay='WRAP'  decimals='0'   showToolTip='0' enableSmartLabels='1' enableRotation='0' bgColor='99CCFF,FFFFFF' bgAlpha='40,100' bgRatio='0,100' bgAngle='360' showBorder='0' startingAngle='70'
		sb.append("<chart showPercentageValues='1' bgColor='edf3ff' caption='上标题' subcaption='年度'>");
		sb.append("<set label='Brazil' value='17' toolText='dddddddddddddddd'/>"); //可自定义显示颜色 颜色类型为 hex 不能有#
		sb.append("<set label='Brazil' value='12'/>");
	//	sb.append("<set label='Brazil' value='18' tooltext='Tom Bowler{br}Score: 523{br}Rank:1'  color='DC143C'/>");
	//	sb.append("<set label='USA' value='8'   color='DC143C'/>");
	//	sb.append("<set label='Australia' value='10'   color='DC143C' />");
	//	sb.append("<set label='Japan' value='16' isSliced='1'/>");
	
		
//		sb.append("<trendLines>"); //设置标准
//		sb.append("<line startValue='15' color='009933' displayvalue='' />");
//		sb.append("</trendLines>");
//		//样式定义
////		sb.append("<styles>");
////		sb.append("<definition>");
////		sb.append(" <style name='CanvasAnim' type='Bevel' />");
////		sb.append("</definition>");
////		sb.append(" <application>");
////		sb.append(" <apply toObject='Background' styles='CanvasAnim' />");
////		sb.append("</application>");   
////		sb.append("</styles>");
//		sb.append("<styles>");
//		sb.append("<definition>");
//		sb.append("<style name='myToolTipFont' type='font' font='Arial' size='12' color='FF5904'/>");
//		sb.append("</definition>");
//		sb.append("<application>");
//		sb.append("<apply toObject='ToolTip' styles='myToolTipFont' />");
//		sb.append("</application>");
//		sb.append("</styles>");
		sb.append("</chart>");

		this.writeBack(response, sb.toString());
		return null;
	}
	/**
	 * 柱状图和 曲线图
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward mSColumnLine3D(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		StringBuffer sb = new StringBuffer();
		sb.append("<chart caption='Business Results 2005 v 2006' xAxisName='Month' yAxisName='Revenue' showValues='0' numberPrefix='$'><categories>");
		sb.append("<category label='Jan' /><category label='Feb' /><category label='Mar' /><category label='Apr' /><category label='May' />");
		sb.append(" <category label='Jun' />	      <category label='Jul' />		      <category label='Aug' />		      <category label='Sep' />");
		sb.append("<category label='Oct' />		      <category label='Nov' />		      <category label='Dec' />		   </categories>");
		sb.append("<dataset seriesName='2006'>		      <set value='27400' />		      <set value='29800'/>		      <set value='25800' />		      <set value='26800' />");
		sb.append(" <set value='29600' />		      <set value='32600' />		      <set value='31800' />		      <set value='36700' />");
		sb.append("<set value='29700' />		      <set value='31900' />		      <set value='34800' />		      <set value='24800' />		   </dataset>		   <dataset seriesName='2005' renderAs='Line'>		      <set value='10000'/>");
		sb.append("<set value='11500'/>		      <set value='12500'/>		      <set value='15000'/>		      <set value='11000' />		      <set value='9800' />		      <set value='11800' />");
		sb.append("<set value='19700' />		      <set value='21700' />		      <set value='21900' />		      <set value='22900' />		      <set value='20800' />");
		sb.append(" </dataset>		   <trendlines>	      <line startValue='26000' color='91C728' displayValue='Target' showOnTop='1'/>		   </trendlines>		</chart> ");
		
		this.writeBack(response, sb.toString());
		return null;
	}
	/**
	 * 曲线图
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward line(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		StringBuffer sb = new StringBuffer();
		//lineDashed 实线、虚线
		//lineAlpha  对比度 0-100 默认100
		//lineColor='DC143C' 线条颜色
		//palette='5' 面板颜色 1-5 五种
		//paletteColors='FF0000,0372AB,FF5904'
		//lineThickness='2' 曲线大小
//		lineThickness                折线的厚度
//		anchorRadius                折线节点半径，数字
//		anchorBgAlpha                折线节点透明度，[0-100]
//		anchorBgColor                折线节点填充颜色，6位16进制颜色值
//		anchorBorderColor            折线节点边框颜色，6位16进制颜色值
		sb.append("<chart showShadow='0' lineDashed='0' lineAlpha='100' anchorBgColor='1D8BD1' palette='1' linecolor='1D8BD1' lineThickness='2' >");
		sb.append("<set label='1' value='6' />");
		sb.append("<set label='2' value='8' />");
		sb.append("<set label='3' value='1' /> ");
		sb.append("<set label='4' value='3' /> ");
		sb.append("<set label='5' value='4' color='DC143C'/> ");
		sb.append("<set label='2' value='8' />");
		sb.append("<set label='3' value='1' /> ");
		sb.append("<set label='4' value='3' /> ");
		sb.append("<set label='5' value='4' /> ");
		sb.append("<vLine color='FF5904' thickness='2' />");
		sb.append(" <set label='6' value='9' /> ");
		sb.append(" <set label='7' value='4' /> ");
		sb.append("<set label='8' value='8' /> ");
		sb.append(" <set label='9' value='1' /> ");
		sb.append("<set label='10' value='3' /> ");
		sb.append("<set label='11' value='6' /> ");
		sb.append("<set label='1' value='6' />");
		sb.append("<set label='2' value='8' />");
		sb.append("<set label='3' value='1' /> ");
		sb.append("<set label='4' value='3' /> ");
		sb.append("<set label='5' value='4' /> ");
		sb.append("<trendLines> ");
				sb.append("<line startValue='6' color='009933' thickness='4'  displayvalue='平均值' />  ");
		sb.append("</trendLines> ");
		sb.append("</chart>");


		this.writeBack(response, sb.toString());
		return null;
	}
	/**
	 * 曲线图2
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward lineGroup(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		StringBuffer sb = new StringBuffer();
		sb.append("<chart caption='Daily Visits' subcaption='多曲线图' lineThickness='1' showValues='0' formatNumberScale='0' anchorRadius='2'   divLineAlpha='20' divLineColor='CC3300' divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='5' alternateHGridColor='CC3300' shadowAlpha='40' labelStep='2' numvdivlines='5' chartRightMargin='35' bgColor='FFFFFF,CC3300' bgAngle='270' bgAlpha='10,10'>");

		sb.append("<categories>");
		sb.append("<category label='8/6/2006' />");
		sb.append("<category label='8/7/2006' />");
		sb.append("<category label='8/8/2006' />");
		sb.append("<category label='8/9/2006' />");
		sb.append("<category label='8/10/2006' />");
		sb.append("<category label='8/11/2006' />");
		sb.append("<category label='8/12/2006' />");
		sb.append("</categories>");
		
		//添加线条1
		sb.append("<dataset seriesName='Offline Marketing' color='1D8BD1' anchorBorderColor='1D8BD1' anchorBgColor='1D8BD1'>");
		sb.append("<set value='1327' /><set value='1826' /><set value='1699' /><set value='1511' /><set value='1904' /><set value='1957' /><set value='1296' />");
		sb.append("</dataset>");
		//线条2
		sb.append("<dataset seriesName='Search' color='F1683C' anchorBorderColor='F1683C' anchorBgColor='F1683C'>");
		sb.append("<set value='1334' /><set value='1857' /><set value='1634' /><set value='1451' /><set value='1804' /><set value='1757' /><set value='1696' />");
		sb.append("</dataset>");

		sb.append("<dataset seriesName='Paid Search' color='2AD62A' anchorBorderColor='2AD62A' anchorBgColor='2AD62A'>");
		sb.append("<set value='850' /><set value='1010' /><set value='1116' /><set value='1234' /><set value='1210' /><set value='1054' /><set value='802' />");
		sb.append("</dataset>");

		sb.append("<dataset seriesName='From Mail' color='DBDC25' anchorBorderColor='DBDC25' anchorBgColor='DBDC25'>");
		sb.append("<set value='541' /><set value='781' /><set value='920' /><set value='754' /><set value='840' /><set value='893' /><set value='451' />");
		sb.append("</dataset>");
	
		sb.append("</chart>");
		this.writeBack(response, sb.toString());
		return null;
	}
	/**
	 * 柱状图
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward columnImage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		StringBuffer sb = new StringBuffer();
		sb.append("<chart showPercentageValues='1' caption='上标题' subcaption='年度' showBorder='0' bgColo='DC143C' >");
		sb.append("<set label='Brazil' value='17' toolText='7777777777'/>"); //可自定义显示颜色 颜色类型为 hex 不能有#
		sb.append("<set label='Brazil' value='12'/>");
		sb.append("<set label='Brazil' value='17' toolText='000000000'/>"); //可自定义显示颜色 颜色类型为 hex 不能有#
		sb.append("<set label='Brazil' value='12'/>");
		sb.append("<set label='Brazil' value='17' toolText='999999999'/>"); //可自定义显示颜色 颜色类型为 hex 不能有#
		sb.append("<set label='Brazil' value='12'/>");
		sb.append("<set label='Brazil' value='17' toolText='999'/>"); //可自定义显示颜色 颜色类型为 hex 不能有#
		sb.append("<set label='Brazil' value='12'/>");
		sb.append("<set label='Brazil' value='12'/>");
		sb.append("<set label='Brazil' value='12'/>");
		sb.append("<set label='Brazil' value='12'/>");
		sb.append("<set label='Brazil' value='12'/>");
		sb.append("</chart>");

		this.writeBack(response, sb.toString());
		return null;
	}
	/**
	 * 分组柱状图
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward columnImageGroup(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		StringBuffer sb = new StringBuffer();
		//palette="2" caption="Country Comparison" shownames="1" showvalues="0" decimals="0" numberPrefix="$" useRoundEdges="1" legendBorderAlpha="0"
		sb.append("<chart palette='2' caption='Country Comparison' shownames='1' showvalues='0' decimals='0' useRoundEdges='1' legendBorderAlpha='0'>");
		sb.append("<categories>");
		sb.append("<category label='Austria' /> ");
		sb.append("<category label='Brazil' /> ");
		sb.append("<category label='France'/> ");
		sb.append("<category label='Germany' /> ");
		sb.append("<category label='china' /> ");
		sb.append("</categories>");
		
		sb.append("<dataset seriesName='1996' color='AFD8F8' showValues='0'>");
		sb.append("<set value='25.34' /> ");
		sb.append("<set value='20.82' /> ");
		sb.append("<set value='17.76' /> ");
		sb.append("<set value='35.15' /> ");
		sb.append("<set value='38.68' /> ");
		sb.append("</dataset>");
		
		sb.append("<dataset seriesName='1997' color='F6BD0F' showValues='0'>");
		sb.append("<set value='25.34' /> ");
		sb.append("<set value='20.82' /> ");
		sb.append("<set value='14.76' /> ");
		sb.append("<set value='34.15' /> ");
		sb.append("<set value='39.68' /> ");
		sb.append("</dataset>");
		
		sb.append("<dataset seriesName='1998' color='8BBA00' showValues='0'>");
		sb.append("<set value='26.34' /> ");
		sb.append("<set value='25.82' /> ");
		sb.append("<set value='27.76' /> ");
		sb.append("<set value='30.15' /> ");
		sb.append("<set value='48.68' /> ");
		sb.append("</dataset>");
		
		
		
		sb.append(" </chart>");

		this.writeBack(response, sb.toString());
		return null;
	}
	
	/**
	 * 环状图形
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward doughnutImage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		StringBuffer sb = new StringBuffer();
		sb.append("<chart palette='2' bgColor='ffffff' showPercentageValues='1' caption='磁盘使用状况' baseFontSize='12'>");
		sb.append("<set label='已使用17GB' value='17' />");
		sb.append("<set label='未使用12GB' value='12' />");
		sb.append("<set label='未分区2GB' value='2'/>");
		sb.append("</chart>");
			
		
		this.writeBack(response, sb.toString());
		return null;
	}
	/**
	 * 区域图
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward areaImage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		StringBuffer sb = new StringBuffer();
		sb.append("<chart caption='Monthly Revenue' xAxisName='Month' yAxisName='Revenue' howValues='0'>");
		//set 数据
		sb.append("<set label='Jan' value='42' /><set label='Feb' value='91' /><set label='Mar' value='72' /><set label='Apr' value='55' /><set label='May' value='81' /><set label='Jun' value='51' /><set label='Jul' value='68' /><set label='Aug' value='42' /><set label='Sep' value='61' /><set label='Oct' value='49' /><set label='Nov' value='53' /><set label='Dec' value='63' />");
	
		sb.append("<trendLines>");
		sb.append("<line startValue='70' color='009933' displayvalue='及格分数线' />");
		sb.append("</trendLines>");
		sb.append("<styles>");
		sb.append("<definition>");
		sb.append("<style name='CanvasAnim' type='animation' param='_xScale' start='0' duration='1' />");
		sb.append("</definition>");
		sb.append("<application>");
		sb.append("<apply toObject='Canvas' styles='CanvasAnim' />");
		sb.append("</application>");
		sb.append("</styles>");
		sb.append("</chart>");
			
		
		this.writeBack(response, sb.toString());
		return null;
	}
	/**
	 * 普通bar 2d 图
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward barImage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		StringBuffer sb = new StringBuffer();
		sb.append("<chart caption='Monthly Unit Sales' xAxisName='Month' yAxisName='Units' showValues='0' decimals='0' formatNumberScale='0' chartRightMargin='30' >");
		sb.append("<set label='Jan' value='462' />");
		sb.append("<set label='Feb' value='857' />");
		sb.append("<set label='Mar' value='671' />");
		sb.append("<set label='Apr' value='494' />");
		sb.append("</chart>");
		this.writeBack(response, sb.toString());
		return null;
	}
	/**
	 * 2d MSBar
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward multiBarImage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		StringBuffer sb = new StringBuffer();
		sb.append("<chart palette='2' caption='Business Results: 2005' yaxisname='Revenue (Millions)' hovercapbg='FFFFFF' toolTipBorder='889E6D' divLineColor='999999' divLineAlpha='80' showShadow='0' canvasBgColor='FEFEFE' canvasBaseColor='FEFEFE' canvasBaseAlpha='50' divLineIsDashed='1' divLineDashLen='1' divLineDashGap='2'  numberSuffix='M' chartRightMargin='30' useRoundEdges='1' legendBorderAlpha='0'>");
		sb.append("<categories>");
		
		//分三个组
		sb.append("<category label='Hardware'/>");
		sb.append("	<category label='Software' />");
		sb.append("<category label='Service' />");
		sb.append("</categories>");
		// 每组数据
		sb.append("<dataset seriesname='Domestic' color='8EAC41'><set value='84' /><set value='207' /><set value='116' /></dataset>");
		sb.append("<dataset seriesname='International' color='607142' ><set value='116' /><set value='237' /><set value='83' /></dataset>");
		sb.append("</chart>");
		this.writeBack(response, sb.toString());
		return null;
	}
	/**
	 * 分组切割 柱状图
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward multiGroupBarImage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		StringBuffer sb = new StringBuffer();
		sb.append("<chart palette='2' showValues='0' caption='Business Results: 2005' yaxisname='Revenue (Millions)' hovercapbg='FFFFFF' toolTipBorder='889E6D' divLineColor='999999' divLineAlpha='80' showShadow='0' canvasBgColor='FEFEFE' canvasBaseColor='FEFEFE' canvasBaseAlpha='50' divLineIsDashed='1' divLineDashLen='1' divLineDashGap='2'  numberSuffix='M' chartRightMargin='30' useRoundEdges='1' legendBorderAlpha='0'>");
		//分三个组
		sb.append("<categories>");
		sb.append("<category label='Hardware'/>");
		sb.append("<category label='Software' />");
		sb.append("<category label='Service' />");
		sb.append("</categories>");
		// 每组数据
		sb.append("<dataset>");
		sb.append("<dataset seriesname='Domestic' color='F6BD0F'><set value='100' /><set value='200' /><set value='150' /></dataset>");
		//sb.append("<dataset seriesname='International' color='607142' ><set value='116' /><set value='237' /><set value='83' /></dataset>");
		sb.append("</dataset>");
		
		sb.append("<dataset>");
		sb.append("<dataset seriesname='Domestic' color='8EAC41'><set value='20' /><set value='100' /><set value='50' /></dataset>");
		sb.append("<dataset seriesname='International' color='8BBA00' ><set value='60' /><set value='50' /><set value='50' /></dataset>");
		sb.append("<dataset seriesname='Domestic' color='A66EDD'><set value='20' /><set value='50' /><set value='50' /></dataset>");
		//sb.append("<dataset seriesname='International' color='607142' ><set value='116' /><set value='237' /><set value='83' /></dataset>");
		sb.append("</dataset>");
		
		
		sb.append("</chart>");
		this.writeBack(response, sb.toString());
		return null;
	}
	/**
	 * 实时返回
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward multiImage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		return null;
	}
	/**
	 * ajax 返回
	 * @param response
	 */
	private void writeBack(HttpServletResponse response,String str){
		try{
		response.setContentType("text/xml");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		java.io.PrintWriter out = response.getWriter();
		out.print(str);
		out.flush();
		out.close();
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}
}
